package cn.eoeit.mmy.bean;


import java.util.List;

public class Pagination<T> {
	// 缺省每页显示的记录数
	public static final int DEFAULT_PAGE_SIZE = 15;
	// 封装分页信息

	private int page;// 当前页
	
	private int countPage;// 总页数
	private int rowFrom;// 开始的记录数
	private int rowTo;// 结束的记录数 ===pageSize

	private int pageSize;// 每页显示的记录数信息
	
	//结合easyUI 中json的返回格式
	private int total;// 总记录数
	private List<T> datas; // 记录信息

	public Pagination() {
		super();
	}

	public Pagination(Integer total) {
		super();
		this.total = total;
	}

	// 封装分页信息操作的构造器 page代表当前页 total 代表总记录数 pageSize代表每页显示的记录数
	public Pagination(int page, int total, int pageSize) {
		super();
		// 总记录数
		if (total < 0) {
			this.total = 0;
		} else {
			this.total = total;
		}
		// 每页显示的记录数
		if (pageSize < 1) {
			this.pageSize = DEFAULT_PAGE_SIZE;
		} else {
			this.pageSize = pageSize;
		}
		// 计算总页数
		this.countPage = this.total % this.pageSize == 0 ? this.total
				/ this.pageSize : this.total / this.pageSize + 1;
		// 获取当前页
		if (page <=0) {
			this.page = 1;
		} else if (page >= this.countPage) {
			this.page = this.countPage;
		} else {
			this.page = page;
		}
		// 计算出开始记录数 和结束记录数
		rowFrom = (this.page - 1) * this.pageSize;
		rowTo = this.pageSize; // 结束记录数由于是采用的hibernate查询所以结束记录数 就是最大记录数
     
	}

	public List<T> getDatas() {
		return datas;
	}

	public void setDatas(List<T> datas) {
		this.datas = datas;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}

	public int getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public int getCountPage() {
		return countPage;
	}

	public void setCountPage(Integer countPage) {
		this.countPage = countPage;
	}

	public int getRowFrom() {
		return rowFrom;
	}

	public void setRowFrom(Integer rowFrom) {
		this.rowFrom = rowFrom;
	}

	public int getRowTo() {
		return rowTo;
	}

	public void setRowTo(Integer rowTo) {
		this.rowTo = rowTo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
}
